<?php
declare (strict_types = 1);

namespace app\api\model;

use app\api\model\Base;
use app\api\model\Week as ModelWeek;
use app\api\model\Chapter as ModelChapter;
use app\api\model\Stage as ModelStage;
use app\api\model\Course as Modelcoure;
/**
 * 分支节点类
 */
class BranchNode extends Base
{

    protected $autoWriteTimestamp = 'datetime';

    /***
     * 
     * 获取上级目录
     */

    public static function getFatherName($week_id,$chapter_id)
    {
        if(! empty($week_id)){
            $data = [];
            $week = ModelWeek::field('id,week_name,stage_id')->find($week_id);
            $stage = ModelStage::field('id,stage,course_id')->find($week->stage_id);
            ModelStage::getStageName($stage);
            $course = Modelcoure::field('id,name')->find($stage->course_id);
            return [
                'code' => 200,
                'message' => '数据获取成功',
                'data' => [
                    'course' => $course,
                    'stage' => $stage,
                    'week' => $week
                ]
            ];
        }else if(! empty($chapter_id)){
            $data = [];
            $chapter = ModelChapter::field('id,title,week_id')->find($chapter_id);
            $week = ModelWeek::field('id,week_name,stage_id')->find($chapter->week_id);
            $stage = ModelStage::field('id,stage,course_id')->find($week->stage_id);
            ModelStage::getStageName($stage);
            $course = Modelcoure::field('id,name')->find($stage->course_id);
            return [
                'code' => 200,
                'message' => '数据获取成功',
                'data' => [
                    'course' => $course,
                    'stage' => $stage,
                    'week' => $week,
                    'chapter' => $chapter
                ]
            ];
        } 
    }

}